package com.td.evo.log.eval;

import java.util.ArrayList;

import com.krakers.evo.log.eval.Evaluator;
import com.krakers.evo.obj.DNA;
import com.td.core.obj.Player;
import com.td.core.obj.TDGame;
import com.td.server.GameController;
import com.td.server.obj.TDBot;
import com.td.server.state.EvoActionState;
import com.td.server.state.EvoBuildingState;

public class TDPathEvaluator implements Evaluator {

	@Override
	public void evaluate(ArrayList<DNA> population) {
		TDGame game = new TDGame(population.size());
		Player[] players = game.getPlayers();
		for(int i = 0; i < population.size(); i++) {
			players[i] = new TDBot(population.get(i), TDBot.PATH);
		}
		
		GameController gc = new GameController(game,
				new EvoActionState(game), new EvoBuildingState(game));
		while(!gc.isGameEnded()) {
			gc.update();
		}
		
		for(int i = 0; i < population.size(); i++) {
			DNA dna = population.get(i);
			dna.setMark(1+players[i].getPoints());
			population.set(i, dna);
		}
	}	
}